home *** CD-ROM | disk | FTP | other *** search
- /* FileM.c */ /* C14 Calculator */
-
- #include "ResourceDefs.h"
- #include "Miscellany.h"
- #include "Globals.h"
- #include "FileM.h"
- #include "Dispatcher.h"
- #include "PredatorPreyData.h"
- #include "calc_wizard.h"
-
- /*static void CloseAppWindow (void);*/
- static void DoSave (void);
- static void DoSaveAs (void);
-
-
- void FileMSeg() {}
-
-
- /*----------*/
- static void DoSaveAs (void)
- {
- SFReply sfInfo;
- short fRefNum;
- StringHandle prompt;
- Str255 promptStr;
- Str255 suggestion;
-
- prompt = GetString (SaveAsPromptID);
- if (prompt != nil) {
- BlockMove (&(**prompt), promptStr, GetHandleSize ((Handle) prompt));
- } else {
- promptStr [0] = 0;
- }
- BlockMove (&(**cur->filename), suggestion, GetHandleSize ((Handle) cur->filename));
-
- if (CreateFile (&sfInfo, promptStr, suggestion, kSignature, kFileType)) {
- CloseAppFile (cur->fileNum);
- if (OpenAppFile (sfInfo.vRefNum, sfInfo.fName, &fRefNum)) {
- SetWTitle (curWindow, sfInfo.fName);
- cur->fileNum = fRefNum;
- cur->volNum = sfInfo.vRefNum;
- SetString (cur->filename, sfInfo.fName);
- WriteAppFile (2,cur->fileNum);
- cur->dirty = false;
- } else { /*should never happen*/
- SetWTitle (curWindow, "\p???");
- cur->fileNum = 0;
- cur->volNum = 0;
- }
- }
- } /*DoSaveAs*/
-
- /*----------*/
- static void DoSave (void)
- {
- if (cur->fileNum == 0) {
- DoSaveAs ();
- } else {
- WriteAppFile (2,cur->fileNum);
- cur->dirty = false;
- }
- } /*DoSave*/
-
-
- /*----------*/
- /*static void CloseAppWindow (void)*/
- /*{*/
- /* enum {saveItem = 1, cancelItem, discardItem};*/
- /**/
- /* Str255 curTitle;*/
- /* short itemNum;*/
- /* Boolean okay;*/
- /**/
- /* okay = true;*/
- /* SetInfo (FrontWindow ());*/
- /* if (cur->dirty) {*/
- /* GetWTitle (curWindow, curTitle);*/
- /* ParamText (curTitle, "\p", "\p", "\p");*/
- /* InitCursor ();*/
- /* itemNum = Alert (SaveID, nil);*/
- /* switch (itemNum) {*/
- /* case saveItem:*/
- /* DoSave ();*/
- /* okay = !errorFlag;*/
- /* break;*/
- /* case discardItem:*/
- /* /*Do nothing»;*/
- /* break;*/
- /* case cancelItem:*/
- /* errorFlag = true;*/
- /* okay = false;*/
- /* break;*/
- /* } /*switch»*/
- /* }*/
- /* if (okay) {*/
- /* DisposeAppData ();*/
- /* if (cur->windowKind == 1) { /* 1st or only window in set »*/
- /* CloseAppFile (cur->fileNum);*/
- /* }*/
- /* CloseCurWindow ();*/
- /* }*/
- /*}*/ /*CloseAppWindow*/
-
- /*----------*/
- void DoClose (void)
- {
- WindowPeek frontPeek;
-
- errorFlag = false;
-
- frontPeek = (WindowPeek) FrontWindow ();
- if (frontPeek->windowKind < 0) {
- CloseDeskAcc (frontPeek->windowKind);
- } else if (frontPeek->windowKind == dialogKind) {
- CloseModelessDialog (FrontWindow ());
- }/* else {*/
- /* CloseAppWindow ();*/
- /* }*/
- } /*DoClose*/
-
-
- /*----------*/
- void DoQuit (void)
- {
- Boolean quitting;
-
- quitting = true;
- while (quitting && (FrontWindow () != nil)) {
- SystemTask ();
- DoClose ();
- if (errorFlag) {
- quitting = false;
- }
- } /*while*/
-
- if (quitting) {
- quittingTime = true;
- }
- } /*DoQuit*/